package com.day1;

import com.alibaba.fastjson.JSON;
import com.entity1.MyUser;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/kuayu")
public class Kuayu extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.doGet(req, resp);
        //响应头里设置Access-Control-Allow-Origin可以实现跨域
        resp.setHeader("Access-Control-Allow-Origin","*");
        resp.getWriter().print("hellokuayu");
        MyUser user=new MyUser();
        user.setId(1);
        user.setUsername("a8");
        user.setAge(20);
        String str = JSON.toJSONString(user);
        String callback = req.getParameter("callback");
        str=callback+"("+str+")";
        resp.getWriter().print(str);
        System.out.println("haha");
    }
}
